home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ThreeDMetafile.c
-
- Contains: 3D viewer support for SimpleText
-
- Version: SimpleText 1.4 or later
-
- Written by: Eiichiro Mikami, Tom Dowdy
-
- Copyright: © 1994-1997 by Apple Computer, Inc., all rights reserved.
-
- File Ownership:
-
- DRI: Tom Dowdy
-
- Other Contact: Jim Negrette
-
- Technology: Macintosh Graphics Group
-
- Writers:
-
- (dmp) Dave Polaschek
- (ted) Tom Dowdy
- (ecs) Eric Schlegel
- (TD) Tom Dowdy
-
- Change History (most recent first):
-
- $Log: ThreeDMetafile.c,v $
- Revision 1.2 1998/11/19 01:16:21 wilkes
- Removed reliance on QuickTime. Most changes were conditionalized with
- ALLOW_QUICKTIME...
-
- Revision 1.1.1.1 1998/03/18 22:56:12 ivory
- Initial checkin of SimpleText.
-
-
- 2 7/29/97 2:05 PM Tom Dowdy
- Removed all of the old and boring refs
-
- 1 7/28/97 11:25 AM Duane Byram
- first added to Source Safe project
-
- <11> 11/26/96 ecs smarter cursor adjustment
- <10> 11/25/96 ted [1604457] Fixing 3d crashing in FAT version.
- <9> 9/9/96 dmp staticfy local functions to eliminate warnings in MWC.
- <8> 7/30/96 ted adding inactive button support
- <7> 5/31/96 ted removing unused local
- <6> 2/8/96 ted Fixing SC compiler problems
- <5> 2/8/96 ted Fixing SC compiler problems
- <4> 1/4/96 ecs compile w/ CodeWarrior
- <3> 10/2/95 TD adding support for SC compiler
- <2> 9/13/95 TD adding commas in INIT portion
- <1> 8/21/95 TD First checked in.
-
- */
-
-
-
- #include "MacIncludes.h"
- #include <String.h>
- #include "ThreeDMetafile.h"
-
-
- #if ALLOW_QUICKTIME
- static GlobalEntry gProcPointers[] =
- {
- {uppViewerLibNewProcInfo, nil},
- {uppViewerLibDisposeProcInfo, nil},
-
- {uppViewerLibUseFileProcInfo, nil},
- {uppViewerLibUseDataProcInfo, nil},
-
- {uppViewerLibWriteFileProcInfo, nil},
- {uppViewerLibWriteDataProcInfo, nil},
-
- {uppViewerLibDrawProcInfo, nil},
-
- {uppViewerLibGetPictProcInfo, nil},
- {uppViewerLibGetButtonRectProcInfo, nil},
-
- {uppViewerLibGetDimensionProcInfo, nil},
-
- {uppViewerLibSetFlagsProcInfo, nil},
- {uppViewerLibGetFlagsProcInfo, nil},
-
- {uppViewerLibSetBoundsProcInfo, nil},
- {uppViewerLibGetBoundsProcInfo, nil},
-
- {uppViewerLibSetPortProcInfo, nil},
- {uppViewerLibGetPortProcInfo, nil},
-
- {uppViewerLibEventProcInfo, nil},
- {uppViewerLibAdjustCursorProcInfo, nil},
-
- {uppViewerLibGetStateProcInfo, nil},
-
- {uppViewerLibClearProcInfo, nil},
- {uppViewerLibCutProcInfo, nil},
- {uppViewerLibCopyProcInfo, nil},
- {uppViewerLibPasteProcInfo, nil}
- };
- #endif
-
-
- // --------------------------------------------------------------------------------------------------------------
- // PRIVATE ROUTINES
- // --------------------------------------------------------------------------------------------------------------
- static UniversalProcPtr MakeARoutineDescriptor(void *theProc, ProcInfoType theProcInfo)
- /*
- The Symantec compiler doesn't like jumping into staticly done routine descriptors,
- so we have to actually allocate them as pointers. Sigh.
- */
- {
- RoutineDescriptor rd = BUILD_ROUTINE_DESCRIPTOR(0, nil);
-
- Ptr newPtr;
-
- rd.routineRecords[0].procInfo = theProcInfo;
- rd.routineRecords[0].procDescriptor = theProc;
- rd.routineRecords[0].ISA = kPowerPCISA + kPowerPCRTA;
- newPtr = NewPtrClear(sizeof(rd));
- if (newPtr)
- BlockMove(&rd, newPtr, sizeof(rd));
- return((UniversalProcPtr) newPtr);
-
- } // MakeARoutineDescriptor
-
- // --------------------------------------------------------------------------------------------------------------
- static void FillInEntryPoints(void)
- {
- #if ALLOW_QUICKTIME
- long result;
-
- if (
- (Gestalt('qd3d', &result) == noErr) &&
- (Gestalt('sysa', &result) == noErr) && (result == 2)
- )
- {
- CFragSymbolClass symClass;
- CFragConnectionID connID;
- Ptr mainAddr;
- Str255 errName;
- long procID = 0;
-
- if (GetSharedLibrary("\pQD3DViewerLib", 'pwpc', 1, &connID, &mainAddr, errName) == noErr)
- {
- FindSymbol(connID, "\pQ3ViewerNew", (Ptr*)&gProcPointers[procID++].entry, &symClass);
- FindSymbol(connID, "\pQ3ViewerDispose", (Ptr*)&gProcPointers[procID++].entry, &symClass);
-
- FindSymbol(connID, "\pQ3ViewerUseFile", (Ptr*)&gProcPointers[procID++].entry, &symClass);
- FindSymbol(connID, "\pQ3ViewerUseData", (Ptr*)&gProcPointers[procID++].entry, &symClass);
-
- FindSymbol(connID, "\pQ3ViewerWriteFile", (Ptr*)&gProcPointers[procID++].entry, &symClass);
- FindSymbol(connID, "\pQ3ViewerWriteData", (Ptr*)&gProcPointers[procID++].entry, &symClass);
-
- FindSymbol(connID, "\pQ3ViewerDraw", (Ptr*)&gProcPointers[procID++].entry, &symClass);
-
- FindSymbol(connID, "\pQ3ViewerGetPict", (Ptr*)&gProcPointers[procID++].entry, &symClass);
- FindSymbol(connID, "\pQ3ViewerGetButtonRect", (Ptr*)&gProcPointers[procID++].entry, &symClass);
-
- FindSymbol(connID, "\pQ3ViewerGetDimension", (Ptr*)&gProcPointers[procID++].entry, &symClass);
-
- FindSymbol(connID, "\pQ3ViewerSetFlags", (Ptr*)&gProcPointers[procID++].entry, &symClass);
- FindSymbol(connID, "\pQ3ViewerGetFlags", (Ptr*)&gProcPointers[procID++].entry, &symClass);
-
- FindSymbol(connID, "\pQ3ViewerSetBounds", (Ptr*)&gProcPointers[procID++].entry, &symClass);
- FindSymbol(connID, "\pQ3ViewerGetBounds", (Ptr*)&gProcPointers[procID++].entry, &symClass);
-
- FindSymbol(connID, "\pQ3ViewerSetPort", (Ptr*)&gProcPointers[procID++].entry, &symClass);
- FindSymbol(connID, "\pQ3ViewerGetPort", (Ptr*)&gProcPointers[procID++].entry, &symClass);
-
- FindSymbol(connID, "\pQ3ViewerEvent", (Ptr*)&gProcPointers[procID++].entry, &symClass);
- FindSymbol(connID, "\pQ3ViewerAdjustCursor", (Ptr*)&gProcPointers[procID++].entry, &symClass);
-
- FindSymbol(connID, "\pQ3ViewerGetState", (Ptr*)&gProcPointers[procID++].entry, &symClass);
-
- FindSymbol(connID, "\pQ3ViewerClear", (Ptr*)&gProcPointers[procID++].entry, &symClass);
- FindSymbol(connID, "\pQ3ViewerCut", (Ptr*)&gProcPointers[procID++].entry, &symClass);
- FindSymbol(connID, "\pQ3ViewerCopy", (Ptr*)&gProcPointers[procID++].entry, &symClass);
- FindSymbol(connID, "\pQ3ViewerPaste", (Ptr*)&gProcPointers[procID++].entry, &symClass);
- }
-
- // build the routine descriptors
- {
- short i;
-
- for (i = 0; i < procID; ++i)
- gProcPointers[i].entry = MakeARoutineDescriptor(gProcPointers[i].entry, gProcPointers[i].info);
- }
-
- // as long as it isn't NIL, we're OK
- if (gProcPointers[0].entry)
- gMachineInfo.haveThreeD = true;
- }
- #endif
- } // FillInEntryPoints
-
- // --------------------------------------------------------------------------------------------------------------
- // OOP INTERFACE ROUTINES
- // --------------------------------------------------------------------------------------------------------------
-
- static OSErr ThreeDCloseWindow(
- WindowPtr pWindow,
- WindowDataPtr pData)
- {
- #pragma unused (pWindow)
-
- #if ALLOW_QUICKTIME
- ViewerLib_Dispose( ((ThreeDDataPtr)pData)->viewerObject);
- #endif
-
- return(noErr);
-
- } // ThreeDCloseWindow
-
- // --------------------------------------------------------------------------------------------------------------
- static OSErr ThreeDGetBalloon(
- WindowPtr pWindow,
- WindowDataPtr pData,
- Point *localMouse,
- short * returnedBalloonIndex,
- Rect *returnedRectangle)
- {
- #pragma unused (pWindow, pData, localMouse, returnedBalloonIndex, returnedRectangle)
-
- *returnedBalloonIndex = iDidTheBalloon;
-
- return(noErr);
-
- } // ThreeDGetBalloon
-
- // --------------------------------------------------------------------------------------------------------------
- static Boolean ThreeDFilterEvent(
- WindowPtr pWindow,
- WindowDataPtr pData,
- EventRecord *pEvent)
- {
- #pragma unused (pWindow)
-
- #if ALLOW_QUICKTIME
- if (pEvent->what == activateEvt)
- {
- if (pEvent->modifiers & activeFlag)
- ViewerLib_SetFlags(((ThreeDDataPtr)pData)->viewerObject, ViewerLib_GetFlags(((ThreeDDataPtr)pData)->viewerObject) | kQ3ViewerActive);
- else
- ViewerLib_SetFlags(((ThreeDDataPtr)pData)->viewerObject, ViewerLib_GetFlags(((ThreeDDataPtr)pData)->viewerObject) & ~kQ3ViewerActive);
- }
-
- return((Boolean)ViewerLib_Event (((ThreeDDataPtr)pData)->viewerObject, pEvent));
- #endif
- return false;
-
- } // ThreeDFilterEvent
-
-
- // --------------------------------------------------------------------------------------------------------------
- static OSErr ThreeDAdjustCursor(WindowPtr pWindow, WindowDataPtr pData, Point *localMouse, RgnHandle globalRgn)
- {
- #pragma unused (pWindow)
-
- OSErr anErr = noErr;
-
- #if ALLOW_QUICKTIME
- ViewerLib_AdjustCursor(((ThreeDDataPtr)pData)->viewerObject, localMouse);
-
- // since we don't know how the Viewer will adjust the cursor, make sure we get continuous calls
- SetEmptyRgn(globalRgn);
- #endif
-
- return(eActionAlreadyHandled);
-
- } // ThreeDAdjustCursor
-
- // --------------------------------------------------------------------------------------------------------------
- static OSErr ThreeDGetCoachRectangle(WindowPtr pWindow, WindowDataPtr pData, Rect *pRect, Ptr name)
- {
- #pragma unused (pWindow)
-
- OSErr anErr = fnfErr;
-
- #if ALLOW_QUICKTIME
- if (strcmp(name, "Camera") == 0)
- anErr = ViewerLib_GetButtonRect(((ThreeDDataPtr)pData)->viewerObject, kQ3ViewerButtonCamera, pRect);
- if (strcmp(name, "Truck") == 0)
- anErr = ViewerLib_GetButtonRect(((ThreeDDataPtr)pData)->viewerObject, kQ3ViewerButtonTruck, pRect);
- if (strcmp(name, "Orbit") == 0)
- anErr = ViewerLib_GetButtonRect(((ThreeDDataPtr)pData)->viewerObject, kQ3ViewerButtonOrbit, pRect);
- if (strcmp(name, "Zoom") == 0)
- anErr = ViewerLib_GetButtonRect(((ThreeDDataPtr)pData)->viewerObject, kQ3ViewerButtonZoom, pRect);
- if (strcmp(name, "Dolly") == 0)
- anErr = ViewerLib_GetButtonRect(((ThreeDDataPtr)pData)->viewerObject, kQ3ViewerButtonDolly, pRect);
- #endif
-
- return(anErr);
-
- } // ThreeDGetCoachRectangle
-
- // --------------------------------------------------------------------------------------------------------------
- void ThreeDGetFileTypes(
- OSType * pFileTypes,
- OSType * pDocumentTypes,
- short * numTypes)
- {
- #if ALLOW_QUICKTIME
- if (!gMachineInfo.haveThreeD)
- FillInEntryPoints();
-
- if (gMachineInfo.haveThreeD)
- {
- pFileTypes[*numTypes] = '3DMF';
- pDocumentTypes[*numTypes] = kThreeDWindow;
- (*numTypes)++;
- }
- #endif
- } // ThreeDGetFileTypes
-
- // --------------------------------------------------------------------------------------------------------------
- static OSErr ThreeDUpdateWindow(WindowPtr pWindow, WindowDataPtr pData)
- {
- #pragma unused (pWindow)
-
- #if ALLOW_QUICKTIME
- ViewerLib_Draw(((ThreeDDataPtr)pData)->viewerObject);
- #endif
-
- return(noErr);
-
- } // ThreeDUpdateWindow
-
- // --------------------------------------------------------------------------------------------------------------
- static OSErr ThreeDAdjustMenus(WindowPtr pWindow, WindowDataPtr pData)
- {
- #pragma unused (pWindow)
-
- OSErr anErr = noErr;
-
- #if ALLOW_QUICKTIME
- if (ViewerLib_GetState(((ThreeDDataPtr)pData)->viewerObject) )
- EnableCommand(cCopy);
- #endif
-
- return(anErr);
-
- } // ThreeDAdjustMenus
-
- // --------------------------------------------------------------------------------------------------------------
- static OSErr ThreeDCommand(WindowPtr pWindow, WindowDataPtr pData, short commandID, long menuResult)
- {
- #pragma unused (menuResult)
-
- OSErr anErr = noErr;
- #if ALLOW_QUICKTIME
- ViewerObject theViewer = ((ThreeDDataPtr)pData)->viewerObject;
-
- SetPort((GrafPtr) GetWindowPort(pWindow));
-
- switch (commandID)
- {
- case cCopy:
- anErr = ViewerLib_Copy(theViewer);
- if (anErr == noErr)
- anErr = eActionAlreadyHandled;
- break;
- } // switch (commandID)
- #endif
- return(anErr);
-
- } // ThreeDCommand
-
- // --------------------------------------------------------------------------------------------------------------
- static OSErr ThreeDMakeWindow(
- WindowPtr pWindow,
- WindowDataPtr pData)
- {
- OSErr anErr = noErr;
- #if ALLOW_QUICKTIME
- ViewerObject viewerObj;
-
- pData->pCloseWindow = (CloseWindowProc) ThreeDCloseWindow;
- pData->pFilterEvent = (FilterEventProc) ThreeDFilterEvent;
- pData->pGetBalloon = (GetBalloonProc) ThreeDGetBalloon;
- pData->pUpdateWindow = (UpdateWindowProc) ThreeDUpdateWindow;
- pData->pAdjustMenus = (AdjustMenusProc) ThreeDAdjustMenus;
- pData->pCommand = (CommandProc) ThreeDCommand;
- pData->pAdjustCursor = (AdjustCursorProc) ThreeDAdjustCursor;
- pData->pGetCoachRectangle = (GetCoachRectangleProc) ThreeDGetCoachRectangle;
-
- pData->dragWindowAligned = 0;
-
- viewerObj = ViewerLib_New((CGrafPtr )pWindow, &pData->contentRect, kQ3ViewerDefault | kQ3ViewerDraggingOff);
-
- if (viewerObj == 0)
- {
- anErr = memFullErr;
- }
- else
- {
- anErr = ViewerLib_UseFile(viewerObj, pData->dataRefNum);
- if (anErr == noErr)
- ((ThreeDDataPtr)pData)->viewerObject = viewerObj;
- else
- ViewerLib_Dispose(viewerObj);
-
- }
- #endif
-
- return(anErr);
-
- } // ThreeDMakeWindow
-
- // --------------------------------------------------------------------------------------------------------------
- OSErr ThreeDPreflightWindow(PreflightPtr pPreflightData)
- {
- #if ALLOW_QUICKTIME
- pPreflightData->continueWithOpen = true;
- pPreflightData->makeProcPtr = ThreeDMakeWindow;
- pPreflightData->resourceID = kThreeDWindowID;
- pPreflightData->storageSize = sizeof(ThreeDDataRecord);
- #endif
-
- return(noErr);
-
- } // ThreeDPreflightWindow
-